from tortoise import Model, fields


class BaseModel(Model):
    """所有的表的基类，统一采用逻辑删除"""

    id = fields.IntField(pk=True)
    """主键, 自增长id"""

    def update(self, data: dict):
        """更新字典中的非空数据到对象

        Args:
            data (dict): 数据源
        """
        if data is not None:
            for k in data:
                if data[k] is not None and hasattr(self, k):
                    setattr(self, k, data[k])

    class Meta:
        abstract = True  # 抽象模型，用于继承


class X(BaseModel):
    class Meta:
        table = x
        table_description = "x"
